package com.yurun.orgclassroommodule.service.Impl;

import com.github.pagehelper.PageHelper;
import com.yurun.commonapi.api.CommonResult;
import com.yurun.commonapi.pojo.Classroom;
import com.yurun.orgclassroommodule.mapper.ClassroomMapper;
import com.yurun.orgclassroommodule.service.ClassroomService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;

@Service
public class ClassroomServiceImpl implements ClassroomService {

    @Autowired
    private ClassroomMapper classroomMapper;


    @Override
    public CommonResult allClassroomInfo(Classroom classroom, int pageNum, int pageSize) {
        // 获取用户所有权限id
        /*List<Integer> resourceId = classroomMapper.getResourcesIdByRoleId(classroomMapper.getRoleId(classroom.getEmployeeId()));

        List<String> resource = new ArrayList<>();
        for (int id : resourceId) { // 添加所有权限
            resource.add(classroomMapper.getResourcesById(id));
        }

        if ( resource.contains("orgAdmin:allClassroomInfo")) { // 机构的所有班级
            PageHelper.startPage(pageNum, pageSize);
            return CommonResult.success(classroomMapper.allClassroomInfo(classroom));
        } else if (resource.contains("branchAdmin:allBranchClassroomInfo")) { // 获取分店所有班级信息

        } else if (resource.contains("teacherAdmin:classroomInfo")) { // 获取自己当班主任班级信息

        } else if (resource.contains("teacherAdmin:selfLessonClassroomInfo")) { // 获取自己代课的班级信息

        }*/


        PageHelper.startPage(pageNum, pageSize);
        return CommonResult.success(classroomMapper.allClassroomInfo(classroom));
    }

    @Override
    public CommonResult addClassroom(Classroom classroom) {
        return CommonResult.success(classroomMapper.addClassroom(classroom));
    }

    @Override
    public CommonResult editClassroom(Classroom classroom) {
        if (classroom.getClassroomName().equals(classroomMapper.getClassName(classroom))) {
            return CommonResult.success(classroomMapper.editClassroom(classroom));
        }
        return CommonResult.success(classroomMapper.editClassroomName(classroom));
    }

    @Override
    public CommonResult getStudentOption(BigInteger organizationId, BigInteger branchId) {
        return CommonResult.success(classroomMapper.getStudentOption(organizationId, branchId));
    }
}
